<?php
    echo $this->Form->create('PayReceive',array('onsubmit'=>'javascript:'.$function.' return false;'));
    if(!empty($this->Form->value('PayReceive.id'))){
        echo  $this->Form->input('id');
    }
?>
<input type="hidden" name="data[PayReceive][data_pagamento]" id="PayReceiveDataPagamento" class="form-control nomargin datepicker" value="<?php echo date('d/m/Y'); ?>" />
<div class="modal-body">
    <div class="row mb5">
        <div class="col-sm-12">
            <label class="control-label text-bold">Descrição:</label>
            <?php echo $this->Form->input('descricao',array('class'=>'form-control','required'=>'required','div'=>false,'label'=>false)) ?>
        </div>
    </div>
    <div class="row mb5">
        <div class="col-sm-6">
            <label class="control-label text-bold">Categoria:</label>
            <div class="input-group ">
                <?php echo $this->Form->select('expense_id',$expenses,array('class'=>'chosen-select','empty'=>'Escolha uma Categoria','div'=>false,'label'=>false,'required'=>'required')) ?>
                <span class="input-group-btn">
                    <button type="button" onclick="novaCategoria();" class="btn btn-default" data-toggle="tooltip" title="" data-original-title="Novo Grupo"><i class="fa fa-gear"></i></button>
                  </span>
            </div>
        </div>
        <div class="col-sm-6">
            <div class="form-group">
                <label class="control-label text-bold">Conta:</label>
                <div class="input-group">
                    <?php echo $this->Form->select('account_id',$accounts,array('class'=>'chosen-select','empty'=>'Escolha uma conta','div'=>false,'label'=>false,'placeholder'=>'Escolha um Conta','required'=>'required')) ?>
                    <span class="input-group-btn">
                    <button type="button" class="btn btn-default" data-toggle="tooltip" title="" data-original-title="Novo Grupo"><i class="fa fa-gear"></i></button>
                  </span>
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-sm-6">
        </div>
        <div class="col-sm-6">
            <div class="ckbox ckbox-success">
                <input type="checkbox" name="data[PayReceive][pago]" value="1" id="sa-input-ContaReceber-cPago"/>
                <label class="control-label text-bold" for="sa-input-ContaReceber-cPago">Laçamento Pago</label>
            </div>
        </div>
    </div>
    <div class="row mb5">
        <div class="col-sm-3">
            <div class="form-group">
                <label class="control-label text-bold">Data Vencimento:</label>
                <div class="input-group">
                    <span class="input-group-addon"><span class="fa fa-calendar"></span></span>
                    <?php echo $this->Form->input('data_vencimento',array('type'=>'text','class'=>'form-control nomargin datepicker','required'=>'required','id'=>'PayReceiveDataVencimento','div'=>false,'label'=>false)) ?>
                </div>
            </div>
        </div>
        <div class="col-sm-3">
            <div class="form-group">
                <label class="control-label text-bold">Valor:</label>
                <div class="input-group">
                    <span class="input-group-addon">R$</span>
                    <?php echo $this->Form->input('valor_doc',array('type'=>'text','class'=>'form-control money text-center','required'=>'required','div'=>false,'label'=>false)) ?>
                </div>
            </div>
        </div>
        <section class="sa-box-dataPagamento">
            <div class="col-sm-3">
                <div class="form-group">
                    <label class="control-label text-bold">Valor a Receber:</label>
                    <div class="input-group">
                        <span class="input-group-addon">R$</span>
                        <input type="text" name="data[PayReceive][valor_pago]" id="PayReceiveValorPago" class="form-control money text-center" value="" />
                    </div>
                </div>
            </div>
        </section>
    </div>
    <div class="row">
        <div class="col-sm-6">
            <div class="ckbox ckbox-success">
                <input type="checkbox" name="data[PayReceive][parcelamento]" onchange="parcelamento(this);" value="1" id="sa-input-ContaReceber-cParcelamento"/>
                <label class="control-label text-bold" for="sa-input-ContaReceber-cParcelamento">Replicar?</label>
            </div>
        </div>
    </div>
</div>
<div class="modal-footer">
    <button type="submit" class="btn btn-success btn-sm" id="sa-btn-bProcesssar" data-toggle="tooltip" title="Salvar Conta(s)" data-original-title="Salvar Conta(s)">Processar</button>
    <button type="button" class="btn btn-default btn-sm"  data-dismiss="modal" data-toggle="tooltip" title="Cancelar e sair" data-original-title="Cancelar e sair">Cancelar</button>
</div>
</section>
<?php
    echo $this->Form->End();
?>
<script>
    jQuery(function(){

        jQuery(".chosen-select").chosen({'width':'100%','white-space':'nowrap'});
        jQuery('.money').mask('###.##0,00', {reverse: true});
        jQuery('.datepicker').datepicker({
            format: 'dd/mm/yyyy'
        });
        jQuery(".sa-box-dataPagamento").hide();
        jQuery("#sa-input-ContaReceber-cPago").click(function(){
            if(this.checked){
                var dataVencimento = SAPReceita.getValueInput('input[name="data[PayReceive][data_vencimento]"]');
                var valorDoc = SAPReceita.getValueInput('input[name="data[PayReceive][valor_doc]"]');
                if( dataVencimento == ''){
                    alert('Informe a data de vencimento');
                    return false;
                }
                if(valorDoc == ''){
                    alert('Informe o valor da conta');
                    return false;
                }
                jQuery(".sa-box-dataPagamento").show('fadeIN');
                jQuery('input[name="data[PayReceive][data_pagamento]"]').val(dataVencimento);
                jQuery('input[name="data[PayReceive][valor_pago]"]').val(valorDoc);

            }else{
                jQuery(".sa-box-dataPagamento").hide('fadeOUT');
            }
        });
    });
</script>